﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using iShoppingBUS;
using iShoppingDTO;

namespace iShopping.Member.UserControl
{
    public partial class MatKhau : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            pnlThanhCong.Visible = false;
            pnlLoi.Visible = false;
        }

        protected void btnLuu_Click(object sender, EventArgs e)
        {
            string maTaiKhoan = Request.QueryString["profile"].ToString().Trim();

            TaiKhoanBUS taiKhoanBus = new TaiKhoanBUS();
            
            if(!String.IsNullOrEmpty(txtMKC.Text))
            {
                TaiKhoanDTO taiKhoanDto = new TaiKhoanDTO();
                taiKhoanDto.TenTaiKhoan = Session["username"].ToString().Trim();
                taiKhoanDto.MatKhau = txtMKC.Text.Trim();
                if (TaiKhoanBUS.checkTaiKhoan(taiKhoanDto))
                {
                    if (!String.IsNullOrEmpty(txtMKM.Text) && !String.IsNullOrEmpty(txtMKMNL.Text))
                    {
                        string matkhauMoi = txtMKM.Text.Trim();
                        string matkhauMoiL = txtMKMNL.Text.Trim();
                        if (matkhauMoi.Equals(matkhauMoiL))
                        {
                            bool result = taiKhoanBus.UpdateTaiKhoanOfMatKhau(maTaiKhoan, matkhauMoi);
                            if(result)
                            {
                                pnlThanhCong.Visible = true;
                                pnlLoi.Visible = false;
                            }
                            else
                            {
                                pnlThanhCong.Visible = false;
                                pnlLoi.Visible = true;
                            }
                        }
                    }
                }
                else
                {
                    pnlThanhCong.Visible = false;
                    pnlLoi.Visible = true;
                }
            }
            

        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            txtMKC.Text = "";
            txtMKM.Text = "";
            txtMKMNL.Text = "";
        }
        
    }
}